package com.ashen.boot.admin.project.system.ck.service.impl;

import com.alibaba.fastjson.JSON;
import com.ashen.boot.admin.commons.utils.QueryWrapperUtils;
import com.ashen.boot.admin.project.system.ck.model.dto.JxcCkDTO;
import com.ashen.boot.admin.project.system.ck.model.entity.JxcCkEntity;
import com.ashen.boot.admin.project.system.ck.mapper.IJxcCkMapper;
import com.ashen.boot.admin.project.system.ck.model.query.JxcCkParams;
import com.ashen.boot.admin.project.system.ck.service.IJxcCkService;
import com.ashen.boot.admin.domain.service.impl.SuperBaseServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hb0730.commons.lang.StringUtils;
import com.hb0730.commons.lang.collection.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Objects;


@Service
public class JxcCkServiceImpl extends SuperBaseServiceImpl<Long, JxcCkParams, JxcCkDTO, JxcCkEntity, IJxcCkMapper> implements IJxcCkService {



  @Override
      public Page<JxcCkDTO> page(@Nonnull JxcCkParams params) {
          QueryWrapper<JxcCkEntity> query = this.query(params);
          if (StringUtils.isNotBlank(params.getCkdm())) {
              query.like(JxcCkEntity.CKDM, params.getCkdm());
          }
          if (StringUtils.isNotBlank(params.getCkmc())) {
              query.like(JxcCkEntity.CKMC, params.getCkmc());
          }
          if (Objects.nonNull(params.getIsEnabled())) {
              query.eq(JxcCkEntity.IS_ENABLED, params.getIsEnabled());
          }
          Page<JxcCkEntity> page = QueryWrapperUtils.getPage(params);
 
          //这是添加排序，sqlserver分页需要
          OrderItem orderItem = OrderItem.desc("ckdm");
          page.addOrder(orderItem);
          System.out.println(JSON.toJSONString(query));
          page = super.page(page, query);
          Page<JxcCkDTO> pageInfo = QueryWrapperUtils.pageToBean(page, JxcCkDTO.class);
          List<JxcCkDTO> records = pageInfo.getRecords();
          if (!CollectionUtils.isEmpty(records)) {
 
          }
          return pageInfo;
      }
}
